import { EntityState, EntityStore, PaginatorPlugin, QueryEntity, StoreConfig } from '@datorama/akita';
import { produce } from 'immer'; 

import { VISIBILITY_FILTER } from "@/models/commonType";
import { FansItem } from '@/models/request/userReq';

export interface RoomEntity extends EntityState<FansItem, string> {
  filter: VISIBILITY_FILTER;
}

@StoreConfig({ name: "rooms", producerFn: produce, idKey: 'roomId' })
export class RoomsStore extends EntityStore<RoomEntity> {
  constructor() {
    super({
      filter: VISIBILITY_FILTER.SHOW_ALL,
    });
  }
}

export class RoomsQuery extends QueryEntity<RoomEntity> {
  filter$ = this.select((state) => state.filter);

  constructor(protected store: RoomsStore) {
    super(store);
  }
}

export const makeStore = (): [RoomsStore, RoomsQuery, PaginatorPlugin<RoomEntity>] => {
  const store = new RoomsStore();
  const query = new RoomsQuery(store);

  const rooms_paginator = new PaginatorPlugin(query)
    .withControls()
    .withRange();

  return [store, query, rooms_paginator];
};
